package com.example.renshiguanli.mapper;

import com.example.renshiguanli.pojo.Emp;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EmpMapper {
    //    查询所有员工
    @Select("select * from emp")
    List<Emp> getAllEmps();

    List<Emp> getEmpAndDept();

//    添加员工
    @Insert(" insert into emp (id, name, age, gender, birthday, IDCard, wedlock, nationId,\n" +
            "                         nativePlace, email, phone, address, deptId, posId,\n" +
            "                         degree, school, edate, workState, workID, conversionTime,workAge,notWorkDate\n" +
            "                        )\n" +
            "        values (#{id}, #{name}, #{age}, #{gender},\n" +
            "                #{birthday}, #{IDCard}, #{wedlock},\n" +
            "                #{nationId},#{nativePlace}, #{email},\n" +
            "                #{phone}, #{address}, #{deptId},\n" +
            "                #{posId},#{degree}, #{school},\n" +
            "                #{edate},#{workState}, #{workID},\n" +
            "                #{conversionTime},#{workAge},#{notWorkDate}\n" +
            "               ) ")
    void add(Emp emp);
//    修改员工
//    根据id展示员工信息
    @Select("select * from emp where id=#{id}")
    Emp findById(Integer id);
//    根据id修改用户信息
    @Update("update emp\n" +
            "        set name = #{name},\n" +
            "            gender = #{gender},\n" +
            "            age = #{age},\n" +
            "            birthday = #{birthday},\n" +
            "            IDCard = #{IDCard},\n" +
            "            wedlock = #{wedlock},\n" +
            "            nationId = #{nationId},\n" +
            "            nativePlace = #{nativePlace},\n" +
            "            email = #{email},\n" +
            "            phone = #{phone},\n" +
            "            address = #{address},\n" +
            "            deptId = #{deptId},\n" +
            "            posId = #{posId},\n" +
            "            degree = #{degree},\n" +
            "            school = #{school},\n" +
            "            edate = #{edate},\n" +
            "            workState = #{workState},\n" +
            "            workID = #{workID},\n" +
            "            conversionTime = #{conversionTime},\n" +
            "            workAge = #{workAge},\n" +
            "            notWorkDate = #{notWorkDate}\n" +
            "        where id = #{id}")
    void update(Emp emp);
//    根据id删除用户
    @Delete("delete from emp where id = #{id}")
    void delete(Integer id);
//    根据名字查询员工信息
    List<Emp> findByName(String name);
}
